# 写一个程序，测试此网络内,
# 192.168.1.1 ~  192.168.1.254 之间的机器，
# 哪些开机，哪些关机
# 用多线程实现

import subprocess
import threading

def ping(host_ip):
    r = subprocess.run('ping -c2 %s &> /dev/null' % host_ip,
                       shell=True)
    if r.returncode == 0:
        print(host_ip, ': up')
    else:
        print(host_ip, ': down')


if __name__ == '__main__':
    # 生成 192.168.1.1 ~  192.168.1.254 范围内的IP
    for x in range(1, 255):
        ipv4 = '192.168.1.%d' % x
        # print("IP:", ipv4)
        # 创建一个线程，执行ping 函数
        t = threading.Thread(target=ping, args=(ipv4,))
        t.start()
        # ping(ipv4)